﻿using System;
using BankCreditPortfolio.DAL.Entities;

namespace BankCreditPortfolio.Models.ClientCabinetModels
{
    public class CreditAgreementModel
    {
        public String Agent { get; set; }
        public String Customer { get; set; }
        public String CreditTariff { get; set; }
        public String CreditAmount { get; set; }
        public String Number { get; set; }
        public String Percentage { get; set; }
        public String Fine { get; set; }
        public String Deposit { get; set; }
        public String DeliveryDate { get; set; }
        public String CreditDays { get; set; }
        public String CreditCurrency { get; set; }
        public String Date { get; set; }


        public CreditAgreementModel MapFrom(AgreementPersistence from)
        {
            Agent = from.Banker.Profile.LastName + " " + from.Banker.Profile.FirstName + " " +
                    from.Banker.Profile.MiddleName;
            Customer = from.Order.Client.Profile.LastName + " " + from.Order.Client.Profile.FirstName + " " +
                    from.Order.Client.Profile.MiddleName;
            CreditTariff = from.Order.Tariff.Title;
            CreditAmount = from.Order.Amount.ToString();
            Number =
                (from.Credit.DeliveryDate.AddYears(from.Order.Tariff.Time.Year - 2000).AddMonths(
                    from.Order.Tariff.Time.Month - 1) - from.Credit.DeliveryDate).Days.ToString();
            Percentage = from.Order.Tariff.CreditPercent.ToString();
            Fine = from.Order.Tariff.Fine.ToString();
            Deposit = from.Credit.Deposit.DepositId.ToString();
            DeliveryDate = from.Credit.DeliveryDate.ToString("MM/dd/yyyy");
            CreditDays = Number;
            CreditCurrency = from.Order.Tariff.Currency.Title;
            Date = from.Credit.DeliveryDate.AddYears(from.Order.Tariff.Time.Year - 2000).AddMonths(
                    from.Order.Tariff.Time.Month - 1).ToString("MM/dd/yyyy");
            return this;
        }
    }
}